package com.study.service;

import com.study.entity.db1.SpringScheduledCronPO;
import com.study.enumeration.StatusEnum;
import com.study.mapper.db1.SpringScheduledCronMapper;
import com.study.util.SpringUtil;

public interface ScheduledOfTask extends Runnable {
	/**
	 * 定时任务方法
	 */
	void execute();

	@Override
	default void run() {
		SpringScheduledCronMapper scheduledCronMapper = SpringUtil.getBean(SpringScheduledCronMapper.class);
		SpringScheduledCronPO scheduledCron = scheduledCronMapper.findByCronKey(this.getClass().getName());
		if (StatusEnum.停用.getCode().equals(scheduledCron.getStatus())) {
			// 任务是禁用状态
			return;
		}
		execute();
	}

}
